package com.chf.job.service.impl;

import com.chf.job.dao.WorkExperMapper;
import com.chf.job.pojo.WorkExper;
import com.chf.job.service.WorkExperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WorkExperServiceImpl implements WorkExperService {
    @Autowired
    private WorkExperMapper workExperMapper;
    /**
     * 根据简历id查询工作经验
     * @param id
     * @return
     */
    @Override
    public List<WorkExper> getByResumeId(Integer id) {
        return workExperMapper.getByResumeId(id);
    }

    /**
     * 添加跟新统一接口
     * @param workExper
     * @return
     */
    @Override
    public int updateWorkExper(WorkExper workExper) {
        if (workExper.getId() == null) {
            WorkExper exper = new WorkExper();
            exper.setResumeId(workExper.getResumeId());
            exper.setCompanyName(workExper.getCompanyName());
            exper.setPosition(workExper.getPosition());
            exper.setStartYear(workExper.getStartYear());
            exper.setStartMonth(workExper.getStartMonth());
            exper.setEntYear(workExper.getEntYear());
            exper.setEndMonth(workExper.getEndMonth());
            return workExperMapper.insertSelective(exper);
        }
        WorkExper exper = new WorkExper();
        exper.setId(workExper.getId());
        exper.setCompanyName(workExper.getCompanyName());
        exper.setPosition(workExper.getPosition());
        exper.setStartYear(workExper.getStartYear());
        exper.setStartMonth(workExper.getStartMonth());
        exper.setEntYear(workExper.getEntYear());
        exper.setEndMonth(workExper.getEndMonth());
        return workExperMapper.updateByPrimaryKeySelective(exper);
    }

    /**
     * 根据id删除工作经验
     * @param workExperId
     * @return
     */
    @Override
    public int deleteById(Integer workExperId) {
        return workExperMapper.deleteByPrimaryKey(workExperId);
    }
}
